-- 小车类
local Object = require("app.mode.Object")

local Car = {}
Car.__index = Car
setmetatable(Car, Object)

Car.CAR_STATIC = 0
Car.CAR_RUNNING = 1

function Car:initView()
    self._sprite = cc.Sprite:createWithSpriteFrame(cc.SpriteFrameCache:getInstance():getSpriteFrameByName("car.png"))
end

function Car:exportData()
    local data = Object.exportData(self)
    data.x, data.y = self:getPosition()
    return data
end

function Car:runAnimate()
    if self:getState() == Car.CAR_RUNNING then
        self._sprite:runAction(
            cc.Sequence:create(
                cc.MoveBy:create(4, cc.p(960, 0)),
                cc.CallFunc:create(
                    function(node, data)
                        self._sprite:removeFromParent()
                        self._scene:removeCar(self)
                    end
                ),
                nil
            )
        )
    elseif self:getState() == Car.CAR_STATIC then
        self._sprite:runAction(cc.MoveBy:create(0.3, cc.p(25, 0)))
    end
end

function Car:getState()
    return self._data.state
end

function Car:setState(val)
    self._data.state = val
end

return Car
